#pragma once


#include <functional>
#include <string>
#include <cstdio>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>

using namespace std;

class Task
{
public:
    typedef function<void(int, struct sockaddr_in&)> func;

    Task()
    {}

    Task(int sockfd, struct sockaddr_in& peer, func f)
    : _sockfd(sockfd),
      _peer(peer),
      _f(f)
    {}

    void operator()()
    {
        _f(_sockfd, _peer);
        close(_sockfd);
    }

private:
    int _sockfd;
    struct sockaddr_in _peer;
    func _f;
};
